package cn.zzuisa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import cn.zzuisa.entity.Invitation;
import cn.zzuisa.entity.Module;
import cn.zzuisa.mapper.ModuleMapper;
import cn.zzuisa.service.InvitationService;
import cn.zzuisa.service.ModuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author frank
 * @since 2019-05-07
 */
@Service
public class ModuleServiceImpl extends ServiceImpl<ModuleMapper, Module> implements ModuleService {
    @Autowired
    InvitationService invitationService;

    @Override
    public List<Map<String, Object>> listModule() {
        List<Map<String, Object>> maps = baseMapper.listModule();
        maps.forEach(item -> {
            List<Invitation> list = invitationService.list(new QueryWrapper<>());
            if(list != null && list.size() > 0) {
                list.stream().max((o1, o2) -> (int) (o1.getId() - o2.getId())).get();
            }
            int count = invitationService.count(new QueryWrapper<Invitation>().eq("module_id", item.get("moduleId")));
            item.put("num",count);
            item.put("newest",list );
        });
        return maps;
    }
}
